/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cassys.actions.assessmentGroupManagement;

import cassys.application.DTOs.AssessmentGroupDTO;
import cassys.domain.classManagement.Student;
import cassys.ejb.clients.AssessmentManagementDelegate;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import java.util.List;

/**
 *
 * @author User
 */
public class CreateAssessmentGroup extends ActionSupport implements ModelDriven<AssessmentGroupDTO> {
    
    
    private AssessmentManagementDelegate assessmentDelegate;
    private AssessmentGroupDTO groupDTO = new AssessmentGroupDTO();
    private String [] checked;

    public CreateAssessmentGroup() {
        assessmentDelegate = new AssessmentManagementDelegate();
    }
    
   
    
    public List<Student> getStudents(){
        return assessmentDelegate.getUngroupedStudent(groupDTO.getAssessmentGroupId());
    }

    public String[] getChecked() {
        return checked;
    }

    public void setChecked(String[] checked) {
        this.checked = checked;
    }
    
    
    
    public String createNewAssessmentGroup() throws Exception {
        long  [] ids = new long[checked.length];
        for(int i=0;i < checked.length;i++){
          ids[i] = Long.valueOf(checked[i]);
        }
        groupDTO.setMembers(ids);
        assessmentDelegate.createGroupAssessment(groupDTO);
        return SUCCESS;
    }
    
    @Override
    public AssessmentGroupDTO getModel() {
        return this.groupDTO;
    }
}
